<template>
    <div>
        <h1 style="text-align:center;">Salary Entry</h1>
        <el-form :inline="true" style="text-align:center;">
            <el-form-item>
              <el-input v-model="year" placeholder="Please enter the year"></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="month" placeholder="Please enter the month"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="success" @click="querySalary">search</el-button>
              <el-button type="primary" @click="addSalary">Enter Salary</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData" border style="width: 100%"> 
            <el-table-column prop="year" label="year" align="center"></el-table-column>
            <el-table-column prop="month" label="month" align="center"></el-table-column>
            <el-table-column prop="realName" label="realName" align="center"></el-table-column>
            <el-table-column prop="basicSalary" label="basicSalary" align="center"></el-table-column>
            <el-table-column prop="postSalary" label="postSalary" align="center"></el-table-column>
            <el-table-column prop="mealSalary" label="mealSalary" align="center"></el-table-column>
            <el-table-column prop="travelSalary" label="travelSalary" align="center"></el-table-column>
            <el-table-column prop="overtimeSalary" label="overtimeSalary" align="center"></el-table-column>
            <el-table-column prop="netSalary" label="netSalary" align="center"></el-table-column>
            <el-table-column prop="status" label="status" align="center">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.status == 0" type="danger">Unconfirmed salary</el-tag>
                    <el-tag v-if="scope.row.status == 1" type="success">Confirmed salary</el-tag>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
        <addSalaryDialog v-if="addSalaryDialogVisible" ref="addSalaryDialog" @refreshDataList="querySalary"></addSalaryDialog>
    </div>
</template>

<script>
  import addSalaryDialog from './addSalaryDialog'
  export default {
    data () {
      return {
        tableData: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        year: '',
        month: '',
        addSalaryDialogVisible: false
      }
    },
    components: {
      addSalaryDialog
    },
    methods: {
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.querySalary()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.querySalary()
      },
      // 获取登录的教师信息
      querySalary () {
        this.$http({
          url: this.$http.adornUrl('/edu/tedusalary/querySalaryByYearMonthPage'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'year': this.year,
            'month': this.month
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.tableData = data.data.list
            this.totalPage = data.data.total
          } else {
            this.tableData = []
            this.totalPage = 0
          }
        })
      },
      // 录入薪资
      addSalary () {
        this.addSalaryDialogVisible = true
        this.$nextTick(() => {
          this.$refs.addSalaryDialog.init()
        })
      }
    }
  }
</script>